/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Aug 30, 2009 9:42:20 PM $
 *
 * Author: Eric Yang
 * Date  : Aug 30, 2009 9:42:20 PM
 *
 */
package com.gooex.web.action.gbuy.order;

import java.util.List;

import com.gooex.domain.base.Order;
import com.gooex.domain.base.OrderCustomer;
import com.gooex.domain.base.OrderVendor;
import com.gooex.domain.base.Product;
import com.gooex.domain.base.Property;
import com.gooex.domain.base.PropertyValue;
import com.gooex.service.base.IProductManager;
import com.gooex.service.base.exception.ExceptionCode;
import com.opensymphony.xwork2.Action;

/**
 * @author Eric Yang
 * @author Adolf
 * @version 1.0
 */
public class ViewOrder extends BaseOrderAction {

	private List<PropertyValue> propertyValues;

	private List<Property> properties;

	private Order order;

	private List<Order> orders;

	private String id;

	private IProductManager productManager;

	private Product product;

	/**
	 * 到增加页面之前需要做的操作
	 */
	public String preAdd() {
		product = productManager.getProduct(this.id);
		return SUCCESS;
	}

	public String getAll() throws Exception {
		orders = orderManager.getOrders(page);
		return Action.SUCCESS;
	}

	/**
	 * 查看订单<br>
	 * 传入参数:id - 订单id<br/>
	 */
	public String viewOrder() throws Exception {
		order = orderManager.getOrder(id);
		if (order == null) {
			addActionError(ExceptionCode.ORDER_NOT_EXISTS);
			return ERROR;
		}
		return SUCCESS;
	}

	/**
	 * 获取当前人对当前订单的订单请求
	 */
	public OrderCustomer getOrderCustomer() {
		if (getCurrentUser() == null || order == null)
			return null;
		return orderManager.getOrderCustomer(order, getCurrentUser());
	}

	/**
	 * 获取当前人对当前订单的订单供应信息
	 */
	public OrderVendor getOrderVendor() {
		if (getCurrentUser() == null || order == null)
			return null;
		return orderManager.getOrderVendor(order, getCurrentUser());
	}

	public String getTopNewOrder() throws Exception {
		orders = orderManager.getTopNewOrders(null, page);
		return SUCCESS;
	}

	// /////////////////
	// // getter\setter
	// /////////////////

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public List<PropertyValue> getPropertyValues() {
		return propertyValues;
	}

	public List<Property> getProperties() {
		return properties;
	}

	public List<Order> getOrders() {
		return orders;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setProductManager(IProductManager productManager) {
		this.productManager = productManager;
	}

	public Product getProduct() {
		return product;
	}

}
